using System;
using System.Collections.Generic;
using System.Text;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.ComponentModel.Design;
using System.Windows.Forms;
using System.ComponentModel;

namespace OpenComposite.EII.Designer.Workflow
{
	public class ExtendedUIService : IExtendedUIService
	{
		#region Initialization
		public ExtendedUIService(IServiceProvider serviceProvider)
		{
			_serviceProvider = serviceProvider;
		}
		#endregion

		#region IExtendedUIService Members

		public void AddAssemblyReference(System.Reflection.AssemblyName assemblyName)
		{
			TypeProvider typeProvider = _serviceProvider.GetService(typeof(ITypeProvider)) as TypeProvider;
			if ( typeProvider != null ) {
				typeProvider.AddAssemblyReference(assemblyName.CodeBase);
			} else {
				throw new NullReferenceException("TypeProvider not available.");
			}
		}

		public void AddDesignerActions(DesignerAction[] actions)
		{
		}

		public System.Windows.Forms.DialogResult AddWebReference(out Uri url, out Type proxyClass)
		{
			url = null;
			proxyClass = null;
			return System.Windows.Forms.DialogResult.Cancel;
		}

		public Type GetProxyClassForUrl(Uri url)
		{
			return null;
		}

		public System.ComponentModel.ITypeDescriptorContext GetSelectedPropertyContext()
		{
			ITypeDescriptorContext context = null;
			ISelectionService selectionService = _serviceProvider.GetService(typeof(ISelectionService)) as ISelectionService;
			PropertyGrid propGrid = _serviceProvider.GetService(typeof(PropertyGrid)) as PropertyGrid;
			if ( propGrid != null ) {
				GridItem item = propGrid.SelectedGridItem;
				System.Workflow.ComponentModel.Activity act = selectionService.PrimarySelection as System.Workflow.ComponentModel.Activity;
				if ( item != null && act != null && act.Site != null ) {
					context = new TypeDescriptorContext(act.Site.Container, act, item.PropertyDescriptor, _serviceProvider);
				} else if ( item != null ) {
					context = new TypeDescriptorContext(null, item.Value, item.PropertyDescriptor, _serviceProvider);
				} else {
					context = new TypeDescriptorContext(null, null, null, _serviceProvider);
				}
			}
			return context;
		}

		public Uri GetUrlForProxyClass(Type proxyClass)
		{
			return null;
		}

		public Dictionary<string, Type> GetXsdProjectItemsInfo()
		{
			return null;
		}

		public bool NavigateToProperty(string propName)
		{
			return false;
		}

		public void RemoveDesignerActions()
		{
			
		}

		public void ShowToolsOptions()
		{
			
		}

		#endregion

		#region Private Members

		#region Variables
		private IServiceProvider _serviceProvider;
		#endregion

		#endregion
	}
}
